<?php

class TypeForm extends Zend_Form
{
	public function __construct($options = null)
	{
		parent::__construct($options);	
		
		// load translator
		$registry = Zend_Registry::getInstance();
		$translate = $registry->get('Zend_Translate');
		
		// set up form
		$this->setName('type');
		$this->setAttrib('id', 'typeForm');
		
		// set up empty validator 
		$validator = new Zend_Validate_NotEmpty();
		$validator->setMessage("This field is not left empty");
		$validator->setTranslator($translate);
		
		$id = new Zend_Form_Element_Hidden('id');
		$type_name = new Zend_Form_Element_Text('nameTypeForm');
		$type_name->setLabel($translate->_("Type name") . ":")
		->setRequired(true)
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->setAttrib('size', 15)
		->addValidator($validator);
		
		$type_name->addValidator($validator);
		
		$access_level = new Zend_Form_Element_Select('levelTypeForm');
		$access_level->setLabel($translate->_("Access level") . ":")
		->setRequired(true)
		->addFilter('StripTags')
		->addFilter('StringTrim')
		->addValidator($validator);	
		;
		$access_levels = $registry->get('access_level_config');
		for($i = 1; $i<=$access_levels->number_of_levels; $i++){
			$level_name = 'level' . $i;
			if(isset($access_levels->$level_name->name))
			$access_level->addMultiOption($i, $access_levels->$level_name->name);
		}
		
		$submit = new Zend_Form_Element_Submit('submit');
		$submit->setAttrib('id', 'submitTypeForm');
		$submit->setLabel($translate->_('Add'));
		$this->addElements(array($id, $type_name, $access_level, $submit));		 
	}
}